package com.zzyl.mapper;

import com.github.pagehelper.Page;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.entity.Device;
import com.zzyl.vo.DeviceVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface DeviceMapper {
    /**
     * 根据设备名称查询设备数量
     * @param deviceName
     * @return
     */
    @Select("select count(*) from zzyl.device where device_name = #{deviceName} limit 1")
    Integer countByDeviceName(String deviceName);

    /**
     * 新增设备
     * @param device
     * @return
     */
    Integer insert(Device device);

    /**
     * 分页查询设备列表
     * @param devicePageQueryDto
     * @return
     */
    Page<DeviceVo> pageQueryDevice(DevicePageQueryDto devicePageQueryDto);

    /**
     * 查询设备详情
     * @param iotId
     * @return
     */
    @Select("select d.* ,su.real_name creator from zzyl.device d left join zzyl.sys_user su on d.create_by = su.id where iot_id = #{iotId} ")
    DeviceVo queryDeviceDetail(String iotId);

    /**
     * 根据设备唯一标识查询设备信息
     * @param iotId
     * @return
     */
    @Select("select * from zzyl.device where iot_id = #{iotId}")
    Device selectDeviceByIotId(String iotId);

    /**
     * 更新设备信息
     * @param device
     */
    void updateDevice(Device device);

    /**
     * 根据设备id查询设备信息
     * @param id
     * @return
     */
    @Select("select * from zzyl.device where id = #{id}")
    Device selectDeviceById(Long id);
}
